package com.git.smp.utils;

import java.text.SimpleDateFormat;
import java.util.Date;

import com.git.smp.entity.SqlInfo;

public class InitSql {

	public static StringBuffer createSql(SqlInfo sqlInfo,StringBuffer sb) {
		
		
		if("01".equals(sqlInfo.getChannel())) {
			sqlInfo.setPubSysCode(sqlInfo.getPubSysCode().length() > 6 ?
			sqlInfo.getPubSysCode().substring(0, 6) : sqlInfo.getPubSysCode());
			sqlInfo.setSystemNo(sqlInfo.getSystemNo().length() > 6 ?
			sqlInfo.getSystemNo().substring(0, 6) : sqlInfo.getSystemNo());
					 
		}
		String pro = "--============================\r\n";
		String pro1 = "--" + sqlInfo.getTransCode() + "," + sqlInfo.getPubSysCode() + "," + sqlInfo.getPubCode()
				+ "\r\n";
		String pro2 = "--============================\r\n";
		String sql1 = "";
		String OSB_ROUTEINFO = "";
		if(sqlInfo.getSystemOrg() == null || "".equals(sqlInfo.getSystemOrg())) {
			
			sql1 = "DELETE FROM OSB_ROUTEINFO where S_SRV_CODE='" + sqlInfo.getPubCode()
			+ "' AND S_SRV_SYSCODE='" + sqlInfo.getPubSysCode() + "' AND S_SRV_TARGETSYSCODE='"+sqlInfo.getSystemNo() +"';\r\n";
			
			OSB_ROUTEINFO = "INSERT INTO OSB_ROUTEINFO (S_SRV_CODE, S_SRV_SYSCODE, S_SRV_ORGCODE, S_SRV_ROUTEPATH, S_SRV_BSCODE, S_SRV_TARGETSYSCODE, S_SRV_BSROUTEPATH, S_SRV_FLAG, CREATE_DATE, CREATE_USER) VALUES ('"
					+ sqlInfo.getPubCode()
					+ "', '"
					+ sqlInfo.getPubSysCode()
					+ "', null, '"
					+ sqlInfo.getLocalPath()
					+ "', '"
					+ sqlInfo.getBusCode()
					+ "', '"
					+ sqlInfo.getSystemNo()
					+ "', '"
					+ sqlInfo.getBusPath()
					+ "', '1', current date, 'admin');\r\n";
		}else {
			sql1 = "DELETE FROM OSB_ROUTEINFO where S_SRV_CODE='" + sqlInfo.getPubCode()
			+ "' AND S_SRV_SYSCODE='" + sqlInfo.getPubSysCode() + "' AND S_SRV_TARGETSYSCODE='"+sqlInfo.getSystemNo() + "' AND S_SRV_ORGCODE='"+sqlInfo.getSystemOrg() +"';\r\n";
			
			OSB_ROUTEINFO = "INSERT INTO OSB_ROUTEINFO (S_SRV_CODE, S_SRV_SYSCODE, S_SRV_ROUTEPATH, S_SRV_BSCODE, S_SRV_TARGETSYSCODE, S_SRV_BSROUTEPATH, S_SRV_ORGCODE, S_SRV_FLAG, CREATE_DATE, CREATE_USER) VALUES ('"
					+ sqlInfo.getPubCode()
					+ "', '"
					+ sqlInfo.getPubSysCode()
					+ "', '"
					+ sqlInfo.getLocalPath()
					+ "', '"
					+ sqlInfo.getBusCode()
					+ "', '"
					+ sqlInfo.getSystemNo()
					+ "', '"
					+ sqlInfo.getBusPath()
					+ "', '"
					+ sqlInfo.getSystemOrg()
					+ "', '1', current date, 'admin');\r\n";
			
		}
		//String time = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
		
		String time ="20180101000000";
		
		String sql2 = "DELETE FROM OSB_SERVICE_CONFIG where S_SRV_CODE='"
				+ sqlInfo.getPubCode() + "';\r\n";
		
		String OSB_SERVICE_CONFIG = "INSERT INTO OSB_SERVICE_CONFIG (S_SRV_CODE, S_SRV_STATUS, S_SRV_EFFICIENT_DATE, S_SRV_EXPIRY_DATE, S_SRV_MONITOR_LOG_FLAG, S_SRV_MONITOR_FLOW_FLAG, S_SRV_MSG_VALIDATE_FLAG, S_SRV_RUN) VALUES ('"
				+ sqlInfo.getPubCode()
				+ "', '1', '" + time +"', '99991230000000', '1', '1', '0', '');\r\n";

		String sql3 = "DELETE FROM OSB_SERVICE_CONSUMER where S_SRV_CODE = '"
				+ sqlInfo.getPubCode() + "' AND (S_TYPE='1' or S_TYPE='3');\r\n";
		String sql3_1 = "DELETE FROM OSB_SERVICE_CONSUMER where S_SRV_CODE = '"
				+ sqlInfo.getPubCode() + "' AND S_TYPE='2' AND  S_VALUE='" + sqlInfo.getPubSysCode()
				+ "';\r\n";
		String OSB_SERVICE_CONSUMER = "INSERT INTO OSB_SERVICE_CONSUMER (S_SRV_CODE, S_TYPE, S_VALUE) VALUES ('"
				+ sqlInfo.getPubCode()
				+ "', '1', '*');\r\nINSERT INTO OSB_SERVICE_CONSUMER (S_SRV_CODE, S_TYPE, S_VALUE) VALUES ('"
				+ sqlInfo.getPubCode()
				+ "', '2', '"
				+ sqlInfo.getPubSysCode()
				+ "');\r\nINSERT INTO OSB_SERVICE_CONSUMER (S_SRV_CODE, S_TYPE, S_VALUE) VALUES ('"
				+ sqlInfo.getPubCode() + "', '3', '*');\r\n";
		
		String sql4="";
		String OSB_CODE_MAPPING="";
		if("01".equals(sqlInfo.getStandardAccess())) {
			sql4 = "DELETE FROM OSB_CODE_MAPPING where M_SRC_CODE='"
					+ sqlInfo.getPubCode() + "' AND M_SRC_SYSCODE='" + sqlInfo.getPubSysCode() + "';\r\n";
			OSB_CODE_MAPPING = "INSERT INTO OSB_CODE_MAPPING (M_SRC_CODE, M_SRC_SYSCODE, M_SRC_SERVCODE, M_TAG_CODE, M_TAG_SYSCODE, M_TAG_SERVCODE, M_FLAG, CREATE_DATE, CREATE_USER) VALUES ('"
					+ sqlInfo.getPubCode()
					+ "', '"
					+ sqlInfo.getPubSysCode()
					+ "', null, '"
					+ sqlInfo.getTransCode()
					+ "', '"
					+ sqlInfo.getPubSysCode()
					+ "', '"
					+ sqlInfo.getBusCode()
					+ "', '0', current date, 'admin');\r\n";
		}else {
			sql4 = "DELETE FROM OSB_CODE_MAPPING where M_TAG_CODE='"
					+ sqlInfo.getPubCode() + "' AND M_SRC_SYSCODE='" + sqlInfo.getPubSysCode() + "';\r\n";
			OSB_CODE_MAPPING = "INSERT INTO OSB_CODE_MAPPING (M_SRC_CODE, M_SRC_SYSCODE, M_SRC_SERVCODE, M_TAG_CODE, M_TAG_SYSCODE, M_TAG_SERVCODE, M_FLAG, CREATE_DATE, CREATE_USER) VALUES ('"
					+ sqlInfo.getTransCode()
					+ "', '"
					+ sqlInfo.getPubSysCode()
					+ "', null, '"
					+ sqlInfo.getPubCode()
					+ "', '"
					+ sqlInfo.getPubSysCode()
					+ "', '"
					+ sqlInfo.getBusCode()
					+ "', '1', current date, 'admin');\r\n";
		}
		
		sb.append(pro).append(pro1).append(pro2).append(sql1)
				.append(OSB_ROUTEINFO).append(sql2).append(OSB_SERVICE_CONFIG)
				.append(sql3).append(sql3_1).append(OSB_SERVICE_CONSUMER)
				.append(sql4).append(OSB_CODE_MAPPING).append("\r\n");
		return sb;
	}
	
public static StringBuffer createOESBSql(SqlInfo sqlInfo,StringBuffer sb) {
		
	/*
	 * String channel = ""; if(sqlInfo.getPubSysCode().length() > 6) { channel =
	 * sqlInfo.getPubSysCode(); }else if(sqlInfo.getSystemNo().length() > 6) {
	 * channel = sqlInfo.getSystemNo(); }
	 * 
	 * 
	 * sqlInfo.setPubSysCode(sqlInfo.getPubSysCode().length() > 6 ?
	 * sqlInfo.getPubSysCode().substring(0, 6) : sqlInfo.getPubSysCode());
	 * sqlInfo.setSystemNo(sqlInfo.getSystemNo().length() > 6 ?
	 * sqlInfo.getSystemNo().substring(0, 6) : sqlInfo.getSystemNo());
	 * 
	 * 
	 * String pro = "--============================\r\n"; String pro1 = "--" +
	 * sqlInfo.getTransCode() + "," + sqlInfo.getPubSysCode() + "," +
	 * sqlInfo.getPubCode() + "\r\n"; String pro2 =
	 * "--============================\r\n"; String sql1 = ""; String OSB_ROUTEINFO
	 * = "";
	 * 
	 * if("".equals(channel)){ if(sqlInfo.getSystemOrg() == null ||
	 * "".equals(sqlInfo.getSystemOrg())) {
	 * 
	 * sql1 = "DELETE FROM OSB_ROUTEINFO where S_SRV_CODE='" + sqlInfo.getPubCode()
	 * + "' AND S_SRV_SYSCODE='" + sqlInfo.getPubSysCode() +
	 * "' AND S_SRV_TARGETSYSCODE='"+sqlInfo.getSystemNo() +"';\r\n";
	 * 
	 * OSB_ROUTEINFO =
	 * "INSERT INTO OSB_ROUTEINFO (S_SRV_CODE, S_SRV_SYSCODE, S_SRV_ORGCODE, S_SRV_ROUTEPATH, S_SRV_BSCODE, S_SRV_TARGETSYSCODE, S_SRV_BSROUTEPATH, S_SRV_FLAG, CREATE_DATE, CREATE_USER) VALUES ('"
	 * + sqlInfo.getPubCode() + "', '" + sqlInfo.getPubSysCode() + "', null, '" +
	 * sqlInfo.getOesbLocalPath() + "', '" + sqlInfo.getBusCode() + "', '" +
	 * sqlInfo.getSystemNo() + "', '" + sqlInfo.getOesbBusPath() +
	 * "', '1', current date, 'admin');\r\n"; }else { sql1 =
	 * "DELETE FROM OSB_ROUTEINFO where S_SRV_CODE='" + sqlInfo.getPubCode() +
	 * "' AND S_SRV_SYSCODE='" + sqlInfo.getPubSysCode() +
	 * "' AND S_SRV_TARGETSYSCODE='"+sqlInfo.getSystemNo() +
	 * "' AND S_SRV_ORGCODE='"+sqlInfo.getSystemOrg() +"';\r\n";
	 * 
	 * OSB_ROUTEINFO =
	 * "INSERT INTO OSB_ROUTEINFO (S_SRV_CODE, S_SRV_SYSCODE, S_SRV_ROUTEPATH, S_SRV_BSCODE, S_SRV_TARGETSYSCODE, S_SRV_BSROUTEPATH, S_SRV_ORGCODE, S_SRV_FLAG, CREATE_DATE, CREATE_USER) VALUES ('"
	 * + sqlInfo.getPubCode() + "', '" + sqlInfo.getPubSysCode() + "', null, '" +
	 * sqlInfo.getOesbLocalPath() + "', '" + sqlInfo.getBusCode() + "', '" +
	 * sqlInfo.getSystemNo() + "', '" + sqlInfo.getOesbBusPath() + "', '" +
	 * sqlInfo.getSystemOrg() + "', '1', current date, 'admin');\r\n";
	 * 
	 * } }else{ if(sqlInfo.getSystemOrg() == null ||
	 * "".equals(sqlInfo.getSystemOrg())) {
	 * 
	 * sql1 = "DELETE FROM OSB_ROUTEINFO_CHANNEL where S_SRV_CODE='" +
	 * sqlInfo.getPubCode() + "' AND S_SRV_SYSCODE='" + sqlInfo.getPubSysCode() +
	 * "' AND S_SRV_TARGETSYSCODE='"+sqlInfo.getSystemNo() +"';\r\n";
	 * 
	 * OSB_ROUTEINFO =
	 * "INSERT INTO OSB_ROUTEINFO_CHANNEL (S_SRV_CODE, S_SRV_SYSCODE, S_SRV_ORGCODE, S_SRV_ROUTEPATH, S_SRV_BSCODE, S_SRV_TARGETSYSCODE, S_SRV_BSROUTEPATH, S_SRV_FLAG, CREATE_DATE, CREATE_USER, CHANNEL) VALUES ('"
	 * + sqlInfo.getPubCode() + "', '" + sqlInfo.getPubSysCode() + "', null, '" +
	 * sqlInfo.getOesbLocalPath() + "', '" + sqlInfo.getBusCode() + "', '" +
	 * sqlInfo.getSystemNo() + "', '" + sqlInfo.getOesbBusPath() +
	 * "', '1', current date, 'admin','"+ channel +"');\r\n"; }else { sql1 =
	 * "DELETE FROM OSB_ROUTEINFO_CHANNEL where S_SRV_CODE='" + sqlInfo.getPubCode()
	 * + "' AND S_SRV_SYSCODE='" + sqlInfo.getPubSysCode() +
	 * "' AND S_SRV_TARGETSYSCODE='"+sqlInfo.getSystemNo() +
	 * "' AND S_SRV_ORGCODE='"+sqlInfo.getSystemOrg() + "' AND CHANNEL='"+ channel +
	 * "';\r\n";
	 * 
	 * OSB_ROUTEINFO =
	 * "INSERT INTO OSB_ROUTEINFO_CHANNEL (S_SRV_CODE, S_SRV_SYSCODE, S_SRV_ROUTEPATH, S_SRV_BSCODE, S_SRV_TARGETSYSCODE, S_SRV_BSROUTEPATH, S_SRV_ORGCODE, S_SRV_FLAG, CREATE_DATE, CREATE_USER, CHANNEL) VALUES ('"
	 * + sqlInfo.getPubCode() + "', '" + sqlInfo.getPubSysCode() + "', null, '" +
	 * sqlInfo.getOesbLocalPath() + "', '" + sqlInfo.getBusCode() + "', '" +
	 * sqlInfo.getSystemNo() + "', '" + sqlInfo.getOesbBusPath() + "', '" +
	 * sqlInfo.getSystemOrg() + "', '1', current date, 'admin','"+ channel
	 * +"');\r\n";
	 * 
	 * } }
	 * 
	 * 
	 * String time = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
	 * 
	 * String sql2 = "DELETE FROM OSB_SERVICE_CONFIG where S_SRV_CODE='" +
	 * sqlInfo.getPubCode() + "';\r\n";
	 * 
	 * String OSB_SERVICE_CONFIG =
	 * "INSERT INTO OSB_SERVICE_CONFIG (S_SRV_CODE, S_SRV_STATUS, S_SRV_EFFICIENT_DATE, S_SRV_EXPIRY_DATE, S_SRV_MONITOR_LOG_FLAG, S_SRV_MONITOR_FLOW_FLAG, S_SRV_MSG_VALIDATE_FLAG, S_SRV_RUN) VALUES ('"
	 * + sqlInfo.getPubCode() + "', '1', '" + time
	 * +"', '99991230000000', '1', '1', '0', '');\r\n";
	 * 
	 * String sql3 = "DELETE FROM OSB_SERVICE_CONSUMER where S_SRV_CODE = '" +
	 * sqlInfo.getPubCode() + "' AND (S_TYPE='1' or S_TYPE='3');\r\n"; String sql3_1
	 * = "DELETE FROM OSB_SERVICE_CONSUMER where S_SRV_CODE = '" +
	 * sqlInfo.getPubCode() + "' AND S_TYPE='2' AND  S_VALUE='" +
	 * sqlInfo.getPubSysCode() + "';\r\n"; String OSB_SERVICE_CONSUMER =
	 * "INSERT INTO OSB_SERVICE_CONSUMER (S_SRV_CODE, S_TYPE, S_VALUE) VALUES ('" +
	 * sqlInfo.getPubCode() +
	 * "', '1', '*');\r\nINSERT INTO OSB_SERVICE_CONSUMER (S_SRV_CODE, S_TYPE, S_VALUE) VALUES ('"
	 * + sqlInfo.getPubCode() + "', '2', '" + sqlInfo.getPubSysCode() +
	 * "');\r\nINSERT INTO OSB_SERVICE_CONSUMER (S_SRV_CODE, S_TYPE, S_VALUE) VALUES ('"
	 * + sqlInfo.getPubCode() + "', '3', '*');\r\n";
	 * 
	 * String sql4=""; String OSB_CODE_MAPPING="";
	 * if("01".equals(sqlInfo.getStandardAccess())) { sql4 =
	 * "DELETE FROM OSB_CODE_MAPPING where M_SRC_CODE='" + sqlInfo.getPubCode() +
	 * "' AND M_SRC_SYSCODE='" + sqlInfo.getPubSysCode() + "';\r\n";
	 * OSB_CODE_MAPPING =
	 * "INSERT INTO OSB_CODE_MAPPING (M_SRC_CODE, M_SRC_SYSCODE, M_SRC_SERVCODE, M_TAG_CODE, M_TAG_SYSCODE, M_TAG_SERVCODE, M_FLAG, CREATE_DATE, CREATE_USER) VALUES ('"
	 * + sqlInfo.getPubCode() + "', '" + sqlInfo.getPubSysCode() + "', null, '" +
	 * sqlInfo.getTransCode() + "', '" + sqlInfo.getPubSysCode() + "', '" +
	 * sqlInfo.getBusCode() + "', '0', current date, 'admin');\r\n"; }else { sql4 =
	 * "DELETE FROM OSB_CODE_MAPPING where M_TAG_CODE='" + sqlInfo.getPubCode() +
	 * "' AND M_SRC_SYSCODE='" + sqlInfo.getPubSysCode() + "';\r\n";
	 * OSB_CODE_MAPPING =
	 * "INSERT INTO OSB_CODE_MAPPING (M_SRC_CODE, M_SRC_SYSCODE, M_SRC_SERVCODE, M_TAG_CODE, M_TAG_SYSCODE, M_TAG_SERVCODE, M_FLAG, CREATE_DATE, CREATE_USER) VALUES ('"
	 * + sqlInfo.getTransCode() + "', '" + sqlInfo.getPubSysCode() + "', null, '" +
	 * sqlInfo.getPubCode() + "', '" + sqlInfo.getPubSysCode() + "', '" +
	 * sqlInfo.getBusCode() + "', '1', current date, 'admin');\r\n"; }
	 * 
	 * sb.append(pro).append(pro1).append(pro2).append(sql1)
	 * .append(OSB_ROUTEINFO).append(sql2).append(OSB_SERVICE_CONFIG)
	 * .append(sql3).append(sql3_1).append(OSB_SERVICE_CONSUMER)
	 * .append(sql4).append(OSB_CODE_MAPPING).append("\r\n"); return sb;
	 */
	
		String time = "20180101000000";
		if("01".equals(sqlInfo.getChannel())) {
			String routeChannel = sqlInfo.getPubSysCode().length() > 6 ? sqlInfo.getPubSysCode() : sqlInfo.getSystemNo();
			sqlInfo.setPubSysCode(sqlInfo.getPubSysCode().length() > 6 ?
			sqlInfo.getPubSysCode().substring(0, 6) : sqlInfo.getPubSysCode());
			sqlInfo.setSystemNo(sqlInfo.getSystemNo().length() > 6 ?
			sqlInfo.getSystemNo().substring(0, 6) : sqlInfo.getSystemNo());
			
			String pro = "--============================\r\n";
			String pro1 = "--" + sqlInfo.getTransCode() + "," + sqlInfo.getPubSysCode() + "," + sqlInfo.getPubCode()
					+ "\r\n";
			String pro2 = "--============================\r\n";
			String sql1 = "";
			String OSB_ROUTEINFO_CHANNEL = "";
			if(sqlInfo.getSystemOrg() == null || "".equals(sqlInfo.getSystemOrg())) {
				
				sql1 = "DELETE FROM OSB_ROUTEINFO_CHANNEL where S_SRV_CODE='" + sqlInfo.getPubCode()
				+ "' AND S_SRV_SYSCODE='" + sqlInfo.getPubSysCode() + "' AND S_SRV_TARGETSYSCODE='"+sqlInfo.getSystemNo() + "' AND CHANNEL='" + routeChannel +"';\r\n";
				
				OSB_ROUTEINFO_CHANNEL = "INSERT INTO OSB_ROUTEINFO_CHANNEL (S_SRV_CODE, S_SRV_SYSCODE, S_SRV_ORGCODE, CHANNEL,  S_SRV_ROUTEPATH, S_SRV_BSCODE, S_SRV_TARGETSYSCODE, S_SRV_BSROUTEPATH, S_SRV_FLAG, CREATE_DATE, CREATE_USER) VALUES ('"
						+ sqlInfo.getPubCode()
						+ "', '"
						+ sqlInfo.getPubSysCode()
						+ "', null, '"
						+ routeChannel
						+ "', '"
						+ sqlInfo.getOesbLocalPath()
						+ "', '"
						+ sqlInfo.getBusCode()
						+ "', '"
						+ sqlInfo.getSystemNo()
						+ "', '"
						+ sqlInfo.getOesbBusPath()
						+ "', '1', current date, 'admin');\r\n";
			}else {
				sql1 = "DELETE FROM OSB_ROUTEINFO_CHANNEL where S_SRV_CODE='" + sqlInfo.getPubCode()
				+ "' AND S_SRV_SYSCODE='" + sqlInfo.getPubSysCode() + "' AND S_SRV_TARGETSYSCODE='"+sqlInfo.getSystemNo() + "' AND S_SRV_ORGCODE='"+sqlInfo.getSystemOrg() + " 'AND CHANNEL=' " + routeChannel +"';\r\n";
				
				OSB_ROUTEINFO_CHANNEL = "INSERT INTO OSB_ROUTEINFO (S_SRV_CODE, S_SRV_SYSCODE, S_SRV_ROUTEPATH, S_SRV_BSCODE, S_SRV_TARGETSYSCODE, S_SRV_BSROUTEPATH, S_SRV_ORGCODE, CHANNEL, S_SRV_FLAG, CREATE_DATE, CREATE_USER) VALUES ('"
						+ sqlInfo.getPubCode()
						+ "', '"
						+ sqlInfo.getPubSysCode()
						+ "', '"
						+ sqlInfo.getOesbLocalPath()
						+ "', '"
						+ sqlInfo.getBusCode()
						+ "', '"
						+ sqlInfo.getSystemNo()
						+ "', '"
						+ sqlInfo.getOesbBusPath()
						+ "', '"
						+ sqlInfo.getSystemOrg()
						+ "','"
						+ routeChannel
						+ "', '1', current date, 'admin');\r\n";
				
			}
			//String time = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
			
			
			
			String sql2 = "DELETE FROM OSB_SERVICE_CONFIG where S_SRV_CODE='"
					+ sqlInfo.getPubCode() + "';\r\n";
			
			String OSB_SERVICE_CONFIG = "INSERT INTO OSB_SERVICE_CONFIG (S_SRV_CODE, S_SRV_STATUS, S_SRV_EFFICIENT_DATE, S_SRV_EXPIRY_DATE, S_SRV_MONITOR_LOG_FLAG, S_SRV_MONITOR_FLOW_FLAG, S_SRV_MSG_VALIDATE_FLAG, S_SRV_RUN) VALUES ('"
					+ sqlInfo.getPubCode()
					+ "', '1', '" + time +"', '99991230000000', '1', '1', '0', '');\r\n";

			String sql3 = "DELETE FROM OSB_SERVICE_CONSUMER where S_SRV_CODE = '"
					+ sqlInfo.getPubCode() + "' AND (S_TYPE='1' or S_TYPE='3');\r\n";
			String sql3_1 = "DELETE FROM OSB_SERVICE_CONSUMER where S_SRV_CODE = '"
					+ sqlInfo.getPubCode() + "' AND S_TYPE='2' AND  S_VALUE='" + sqlInfo.getPubSysCode()
					+ "';\r\n";
			String OSB_SERVICE_CONSUMER = "INSERT INTO OSB_SERVICE_CONSUMER (S_SRV_CODE, S_TYPE, S_VALUE) VALUES ('"
					+ sqlInfo.getPubCode()
					+ "', '1', '*');\r\nINSERT INTO OSB_SERVICE_CONSUMER (S_SRV_CODE, S_TYPE, S_VALUE) VALUES ('"
					+ sqlInfo.getPubCode()
					+ "', '2', '"
					+ sqlInfo.getPubSysCode()
					+ "');\r\nINSERT INTO OSB_SERVICE_CONSUMER (S_SRV_CODE, S_TYPE, S_VALUE) VALUES ('"
					+ sqlInfo.getPubCode() + "', '3', '*');\r\n";
			
			String sql4="";
			String OSB_CODE_MAPPING="";
			if("01".equals(sqlInfo.getOesbStandardAccess())) {
				sql4 = "DELETE FROM OSB_CODE_MAPPING where M_SRC_CODE='"
						+ sqlInfo.getPubCode() + "' AND M_SRC_SYSCODE='" + sqlInfo.getPubSysCode() + "';\r\n";
				OSB_CODE_MAPPING = "INSERT INTO OSB_CODE_MAPPING (M_SRC_CODE, M_SRC_SYSCODE, M_SRC_SERVCODE, M_TAG_CODE, M_TAG_SYSCODE, M_TAG_SERVCODE, M_FLAG, CREATE_DATE, CREATE_USER) VALUES ('"
						+ sqlInfo.getPubCode()
						+ "', '"
						+ sqlInfo.getPubSysCode()
						+ "', null, '"
						+ sqlInfo.getTransCode()
						+ "', '"
						+ sqlInfo.getPubSysCode()
						+ "', '"
						+ sqlInfo.getBusCode()
						+ "', '0', current date, 'admin');\r\n";
			}else {
				sql4 = "DELETE FROM OSB_CODE_MAPPING where M_TAG_CODE='"
						+ sqlInfo.getPubCode() + "' AND M_SRC_SYSCODE='" + sqlInfo.getPubSysCode() + "';\r\n";
				OSB_CODE_MAPPING = "INSERT INTO OSB_CODE_MAPPING (M_SRC_CODE, M_SRC_SYSCODE, M_SRC_SERVCODE, M_TAG_CODE, M_TAG_SYSCODE, M_TAG_SERVCODE, M_FLAG, CREATE_DATE, CREATE_USER) VALUES ('"
						+ sqlInfo.getTransCode()
						+ "', '"
						+ sqlInfo.getPubSysCode()
						+ "', null, '"
						+ sqlInfo.getPubCode()
						+ "', '"
						+ sqlInfo.getPubSysCode()
						+ "', '"
						+ sqlInfo.getBusCode()
						+ "', '1', current date, 'admin');\r\n";
			}
			
			sb.append(pro).append(pro1).append(pro2).append(sql1)
					.append(OSB_ROUTEINFO_CHANNEL).append(sql2).append(OSB_SERVICE_CONFIG)
					.append(sql3).append(sql3_1).append(OSB_SERVICE_CONSUMER)
					.append(sql4).append(OSB_CODE_MAPPING).append("\r\n");
			
			
		}else {
			String pro = "--============================\r\n";
			String pro1 = "--" + sqlInfo.getTransCode() + "," + sqlInfo.getPubSysCode() + "," + sqlInfo.getPubCode()
					+ "\r\n";
			String pro2 = "--============================\r\n";
			String sql1 = "";
			String OSB_ROUTEINFO = "";
			if(sqlInfo.getSystemOrg() == null || "".equals(sqlInfo.getSystemOrg())) {
				
				sql1 = "DELETE FROM OSB_ROUTEINFO where S_SRV_CODE='" + sqlInfo.getPubCode()
				+ "' AND S_SRV_SYSCODE='" + sqlInfo.getPubSysCode() + "' AND S_SRV_TARGETSYSCODE='"+sqlInfo.getSystemNo() +"';\r\n";
				
				OSB_ROUTEINFO = "INSERT INTO OSB_ROUTEINFO (S_SRV_CODE, S_SRV_SYSCODE, S_SRV_ORGCODE, S_SRV_ROUTEPATH, S_SRV_BSCODE, S_SRV_TARGETSYSCODE, S_SRV_BSROUTEPATH, S_SRV_FLAG, CREATE_DATE, CREATE_USER) VALUES ('"
						+ sqlInfo.getPubCode()
						+ "', '"
						+ sqlInfo.getPubSysCode()
						+ "', null, '"
						+ sqlInfo.getOesbLocalPath()
						+ "', '"
						+ sqlInfo.getBusCode()
						+ "', '"
						+ sqlInfo.getSystemNo()
						+ "', '"
						+ sqlInfo.getOesbBusPath()
						+ "', '1', current date, 'admin');\r\n";
			}else {
				sql1 = "DELETE FROM OSB_ROUTEINFO where S_SRV_CODE='" + sqlInfo.getPubCode()
				+ "' AND S_SRV_SYSCODE='" + sqlInfo.getPubSysCode() + "' AND S_SRV_TARGETSYSCODE='"+sqlInfo.getSystemNo() + "' AND S_SRV_ORGCODE='"+sqlInfo.getSystemOrg() +"';\r\n";
				
				OSB_ROUTEINFO = "INSERT INTO OSB_ROUTEINFO (S_SRV_CODE, S_SRV_SYSCODE, S_SRV_ROUTEPATH, S_SRV_BSCODE, S_SRV_TARGETSYSCODE, S_SRV_BSROUTEPATH, S_SRV_ORGCODE, S_SRV_FLAG, CREATE_DATE, CREATE_USER) VALUES ('"
						+ sqlInfo.getPubCode()
						+ "', '"
						+ sqlInfo.getPubSysCode()
						+ "', '"
						+ sqlInfo.getOesbLocalPath()
						+ "', '"
						+ sqlInfo.getBusCode()
						+ "', '"
						+ sqlInfo.getSystemNo()
						+ "', '"
						+ sqlInfo.getOesbBusPath()
						+ "', '"
						+ sqlInfo.getSystemOrg()
						+ "', '1', current date, 'admin');\r\n";
				
			}
			//String time = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
			
			String sql2 = "DELETE FROM OSB_SERVICE_CONFIG where S_SRV_CODE='"
					+ sqlInfo.getPubCode() + "';\r\n";
			
			String OSB_SERVICE_CONFIG = "INSERT INTO OSB_SERVICE_CONFIG (S_SRV_CODE, S_SRV_STATUS, S_SRV_EFFICIENT_DATE, S_SRV_EXPIRY_DATE, S_SRV_MONITOR_LOG_FLAG, S_SRV_MONITOR_FLOW_FLAG, S_SRV_MSG_VALIDATE_FLAG, S_SRV_RUN) VALUES ('"
					+ sqlInfo.getPubCode()
					+ "', '1', '" + time +"', '99991230000000', '1', '1', '0', '');\r\n";

			String sql3 = "DELETE FROM OSB_SERVICE_CONSUMER where S_SRV_CODE = '"
					+ sqlInfo.getPubCode() + "' AND (S_TYPE='1' or S_TYPE='3');\r\n";
			String sql3_1 = "DELETE FROM OSB_SERVICE_CONSUMER where S_SRV_CODE = '"
					+ sqlInfo.getPubCode() + "' AND S_TYPE='2' AND  S_VALUE='" + sqlInfo.getPubSysCode()
					+ "';\r\n";
			String OSB_SERVICE_CONSUMER = "INSERT INTO OSB_SERVICE_CONSUMER (S_SRV_CODE, S_TYPE, S_VALUE) VALUES ('"
					+ sqlInfo.getPubCode()
					+ "', '1', '*');\r\nINSERT INTO OSB_SERVICE_CONSUMER (S_SRV_CODE, S_TYPE, S_VALUE) VALUES ('"
					+ sqlInfo.getPubCode()
					+ "', '2', '"
					+ sqlInfo.getPubSysCode()
					+ "');\r\nINSERT INTO OSB_SERVICE_CONSUMER (S_SRV_CODE, S_TYPE, S_VALUE) VALUES ('"
					+ sqlInfo.getPubCode() + "', '3', '*');\r\n";
			
			String sql4="";
			String OSB_CODE_MAPPING="";
			if("01".equals(sqlInfo.getOesbStandardAccess())) {
				sql4 = "DELETE FROM OSB_CODE_MAPPING where M_SRC_CODE='"
						+ sqlInfo.getPubCode() + "' AND M_SRC_SYSCODE='" + sqlInfo.getPubSysCode() + "';\r\n";
				OSB_CODE_MAPPING = "INSERT INTO OSB_CODE_MAPPING (M_SRC_CODE, M_SRC_SYSCODE, M_SRC_SERVCODE, M_TAG_CODE, M_TAG_SYSCODE, M_TAG_SERVCODE, M_FLAG, CREATE_DATE, CREATE_USER) VALUES ('"
						+ sqlInfo.getPubCode()
						+ "', '"
						+ sqlInfo.getPubSysCode()
						+ "', null, '"
						+ sqlInfo.getTransCode()
						+ "', '"
						+ sqlInfo.getPubSysCode()
						+ "', '"
						+ sqlInfo.getBusCode()
						+ "', '0', current date, 'admin');\r\n";
			}else {
				sql4 = "DELETE FROM OSB_CODE_MAPPING where M_TAG_CODE='"
						+ sqlInfo.getPubCode() + "' AND M_SRC_SYSCODE='" + sqlInfo.getPubSysCode() + "';\r\n";
				OSB_CODE_MAPPING = "INSERT INTO OSB_CODE_MAPPING (M_SRC_CODE, M_SRC_SYSCODE, M_SRC_SERVCODE, M_TAG_CODE, M_TAG_SYSCODE, M_TAG_SERVCODE, M_FLAG, CREATE_DATE, CREATE_USER) VALUES ('"
						+ sqlInfo.getTransCode()
						+ "', '"
						+ sqlInfo.getPubSysCode()
						+ "', null, '"
						+ sqlInfo.getPubCode()
						+ "', '"
						+ sqlInfo.getPubSysCode()
						+ "', '"
						+ sqlInfo.getBusCode()
						+ "', '1', current date, 'admin');\r\n";
			}
			
			sb.append(pro).append(pro1).append(pro2).append(sql1)
					.append(OSB_ROUTEINFO).append(sql2).append(OSB_SERVICE_CONFIG)
					.append(sql3).append(sql3_1).append(OSB_SERVICE_CONSUMER)
					.append(sql4).append(OSB_CODE_MAPPING).append("\r\n");
			
		}
		return sb;
	}
	

}
